package com.jacklei;

import com.jacklei.util.ArrUtil;

import java.util.Arrays;

//插入排序
public class InsertionSort {
    public static void main(String[] args) {
        int[] arr = ArrUtil.getRandomArr();
        int[] arr1 = ArrUtil.copyArr(arr);
        Arrays.sort(arr);
        sort(arr1);
        ArrUtil.checkArr(arr,arr1);
        ArrUtil.seeArr(arr,arr1);

    }

    public static void sort(int[] arr){
        for (int i = 0; i < arr.length-1; i++){
            int insetIndex = i+1;
            while(insetIndex > 0 && arr[insetIndex] < arr[insetIndex-1]){
                ArrUtil.swap(arr, insetIndex-1,insetIndex--);
            }
        }

    }
}
